package com.atcd.mq.demo1.two;

import com.atcd.mq.demo1.rabbitmqUtil.RabbitMqUtils;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;


//工作模式的消费者(相当于之前的消费者)
public class Worker01 {
 private static final String QUEUE_NAME="hello";
 public static void main(String[] args) throws Exception {
 Channel channel = RabbitMqUtils.getChannel();
 DeliverCallback deliverCallback=(consumerTag, delivery)->{
 String receivedMessage = new String(delivery.getBody());
 System.out.println("接收到消息:"+receivedMessage);

  //拒绝应答，让消息重新放入队列，(轮训之后)直到手动应答成功
   channel.basicNack(delivery.getEnvelope().getDeliveryTag(),false,true);
 };
 CancelCallback cancelCallback=(consumerTag)->{
 System.out.println(consumerTag+"消费者取消消费接口回调逻辑");
 };
  System.out.println("C1 消费者启动等待消费......");

  boolean autoAck=false;
  channel.basicConsume(QUEUE_NAME,autoAck,deliverCallback,cancelCallback);
 }
}
